home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 15 / CU Amiga Magazine's Super CD-ROM 15 (1997)(EMAP Images)(GB)[!][issue 1997-10].iso / CUCD / Utilities / Post / Source / Parse.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-04-20  |  13.1 KB  |  433 lines

  1. #include "PostPre.h"
  2. #include "Global.h"
  3.  
  4. #define    TEMPLATE1            "STARTUP-FILES/M,X-PAGESIZE=X/K/N,Y-PAGESIZE=Y/K/N,\
  5. X-OFFSET=XOFF/K/N,Y-OFFSET=YOFF/K/N,X-DENSITY=XDEN/K/N,Y-DENSITY=YDEN/K/N,\
  6. DENSITY=DEN/K/N,BW/S,RGB/S,CMYK/S,FONTMEM/K/N,HALFTONEMEM/K/N,VIRTUALMEM/K/N,\
  7. LINEMEM/K/N,BANDSIZE/K/N,IFF-FILE=IFF/K,PRINTER/S,FILE/K,FROM/K/N,TO/K/N,\
  8. NOFORMFEED/S,CENTERPAGE/S,PRINT-DENSITY=PRDEN/K/N,TEMPPATH/K,GRAPHICCARD/S,\
  9. VERBOSE/S,CONWIN/S,CUSTOMSCREEN/S,PUBSCREEN/K,OPTFILE/K,BUFSIZE/K/N"
  10.  
  11. #define    TEMPLATE2            "STARTUP-FILES/M,X-PAGESIZE=X/K/N,Y-PAGESIZE=Y/K/N,\
  12. X-OFFSET=XOFF/K/N,Y-OFFSET=YOFF/K/N,X-DENSITY=XDEN/K/N,Y-DENSITY=YDEN/K/N,\
  13. DENSITY=DEN/K/N,BW/S,RGB/S,CMYK/S,FONTMEM/K/N,HALFTONEMEM/K/N,VIRTUALMEM/K/N,\
  14. LINEMEM/K/N"
  15.  
  16. #define    OPT_FILES            0
  17. #define    OPT_X                    1
  18. #define    OPT_Y                    2
  19. #define    OPT_XOFF                3
  20. #define    OPT_YOFF                4
  21. #define    OPT_XDEN                5
  22. #define    OPT_YDEN                6
  23. #define    OPT_DEN                7
  24. #define    OPT_BW                8
  25. #define    OPT_RGB                9
  26. #define    OPT_CMYK                10
  27. #define    OPT_FONTM            11
  28. #define    OPT_HALFTM            12
  29. #define    OPT_VM                13
  30. #define    OPT_LINEMEM            14
  31. #define    OPT_BAND                15
  32. #define    OPT_IFF                16
  33. #define    OPT_PRINTER            17
  34. #define    OPT_FILE                18
  35. #define    OPT_FROM                19
  36. #define    OPT_TO                20
  37. #define    OPT_NOFF                21
  38. #define    OPT_CENTER            22
  39. #define    OPT_PRDEN            23
  40. #define    OPT_PATH                24
  41. #define    OPT_GRAPHICCARD    25
  42. #define    OPT_VERBOSE            26
  43. #define    OPT_CONWIN            27
  44. #define    OPT_SCREEN            28
  45. #define    OPT_PUBSCREEN        29
  46. #define    OPT_OPTFILE            30
  47. #define    OPT_BUFSIZE            31
  48.  
  49. #define    OPT_COUNT            32
  50.  
  51.  
  52. /*#define    OUTPUT_OPTS*/
  53.  
  54. LONG    opts[OPT_COUNT];
  55.  
  56. int    parse(int argc, struct RDArgs *rdargs)
  57. {
  58.     struct    RDArgs *argsptr;
  59.     struct    DiskObject *diskobj;
  60.     struct    startupnode *startupnode;
  61.     char        **sptr, *line, *filename, diskobjname[256], diskobjpath[256-30];
  62.     UBYTE        **toolarray;
  63.     BOOL        bw = FALSE, rgb = FALSE, cmyk = FALSE, depth_error = FALSE;
  64.     int        i;
  65. #ifdef OUTPUT_OPTS
  66.     struct    Node    *node;
  67. #endif
  68.  
  69.     if(argc == 0)
  70.     {
  71.         if (_WBenchMsg && _WBenchMsg->sm_NumArgs)
  72.         {
  73.             NameFromLock(_WBenchMsg->sm_ArgList[_WBenchMsg->sm_NumArgs-1].wa_Lock, diskobjpath, 255-30);
  74.             getfullfilename(diskobjname, diskobjpath, _WBenchMsg->sm_ArgList[_WBenchMsg->sm_NumArgs-1].wa_Name);
  75.             IconBase = OpenLibrary("icon.library", 0);
  76.             if (IconBase)
  77.             {
  78.                 diskobj = GetDiskObject(diskobjname);
  79.                 if(diskobj)
  80.                 {
  81.                     toolarray = (UBYTE **) diskobj->do_ToolTypes;
  82.                     line = FindToolType(toolarray, "IFF");
  83.                     if(line)
  84.                     {
  85.                         argiff = TRUE;
  86.                         strcpy(Options.PostOpts.iffname, line);
  87.                         copy_options(&Options, &IffOptions);
  88.                         Options.PostOpts.allpages = TRUE;
  89.                         Options.PostOpts.bandrendering = FALSE;
  90.                     }
  91.                     argprint = (FindToolType(toolarray, "PRINTER")) ? TRUE : FALSE;
  92.                     if(argprint)
  93.                     {
  94.                         copy_options(&Options, &PrintOptions);
  95.                         Options.PostOpts.centerpage = FALSE;
  96.                         Options.PostOpts.formfeed = TRUE;
  97.                         Options.PostOpts.allpages = TRUE;
  98.                         Options.PostOpts.bandrendering = FALSE;
  99.                     }
  100.                     line = FindToolType(toolarray, "STARTUP-FILES");
  101.                     if(line)
  102.                     {
  103.                         free_list(&Options.startuplist);
  104.                         filename = strtok(line, ",");
  105.                         while(filename != NULL)
  106.                         {
  107.                             if(!strcmp(filename, "*"))
  108.                             {
  109.                                 okmsg("'*' is not a valid filename!");
  110.                                 filename = strtok(NULL, ",");                                
  111.                                 continue;
  112.                             }
  113.                             startupnode = (struct startupnode *) malloc(sizeof(struct startupnode));
  114.                             strcpy(startupnode->name, filename);
  115.                             startupnode->linknode.ln_Name = startupnode->name;
  116.                             AddTail(&Options.startuplist, (struct Node *) startupnode);
  117.                             filename = strtok(NULL, ",");
  118.                         }
  119.                     }
  120.                     argverbose = argcon = (FindToolType(toolarray, "VERBOSE")) ? TRUE : FALSE;
  121.                     Options.PostOpts.formfeed = (FindToolType(toolarray, "NOFORMFEED")) ? FALSE : TRUE;
  122.                     Options.PostOpts.centerpage = (FindToolType(toolarray, "CENTERPAGE")) ? TRUE : FALSE;
  123.                     if(FindToolType(toolarray, "CUSTOMSCREEN")) Options.Screen.custscreen = TRUE;
  124.                     line = FindToolType(toolarray, "PUBSCREEN");
  125.                     if(line)
  126.                     {
  127.                         if(strlen(line) > MAXPUBSCREENNAME)
  128.                         {
  129.                             okmsg("pubscreenname too long!");
  130.                         }
  131.                         else
  132.                         {
  133.                             Options.Screen.custscreen = FALSE;
  134.                             strcpy(pubscreenname, line);
  135.                         }
  136.                     }
  137.                     line = FindToolType(toolarray, "X");
  138.                     if(line)
  139.                     {
  140.                         Options.PostOpts.width = atoi(line);
  141.                     }
  142.                     line = FindToolType(toolarray, "Y");
  143.                     if(line) Options.PostOpts.height = atoi(line);
  144.                     line = FindToolType(toolarray, "BANDSIZE");
  145.                     if(line)
  146.                     {
  147.                         Options.PostOpts.bandsize = atoi(line);
  148.                         Options.PostOpts.bandrendering = TRUE;
  149.                     }
  150.                     line = FindToolType(toolarray, "XOFF");
  151.                     if(line) Options.PostOpts.xoff = atoi(line);
  152.                     line = FindToolType(toolarray, "YOFF");
  153.                     if(line) Options.PostOpts.yoff = atoi(line);
  154.                     line = FindToolType(toolarray, "XDEN");
  155.                     if(line) Options.PostOpts.xdpi = atoi(line);
  156.                     line = FindToolType(toolarray, "YDEN");
  157.                     if(line) Options.PostOpts.ydpi = atoi(line);
  158.                     line = FindToolType(toolarray, "DEN");
  159.                     if(line)
  160.                     {
  161.                         if(FindToolType(toolarray, "XDEN") ||
  162.                             FindToolType(toolarray, "XDEN"))
  163.                         {
  164.                             okmsg("You can't specify DEN when XDEN or YDEN is specified!");
  165.                         }
  166.                         else Options.PostOpts.xdpi = Options.PostOpts.ydpi = atoi(line);
  167.                     }
  168.                     line = FindToolType(toolarray, "PRDEN");
  169.                     if(line) Options.PostOpts.prden = atoi(line);
  170.                     bw = (FindToolType(toolarray, "BW")) ? TRUE : FALSE;
  171.                     rgb = (FindToolType(toolarray, "RGB")) ? TRUE : FALSE;
  172.                     cmyk = (FindToolType(toolarray, "CMYK")) ? TRUE : FALSE;
  173.                     line = FindToolType(toolarray, "FONTMEM");
  174.                     if(line) Options.PostOpts.fonts = atoi(line);
  175.                     line = FindToolType(toolarray, "HALFETONMEM");
  176.                     if(line) Options.PostOpts.htone = atoi(line);
  177.                     line = FindToolType(toolarray, "VIRTUALMEM");
  178.                     if(line) Options.PostOpts.vm = atoi(line);
  179.                     line = FindToolType(toolarray, "LINEMEM");
  180.                     if(line) Options.PostOpts.paths = atoi(line);
  181.                     line = FindToolType(toolarray, "TEMPPATH");
  182.                     if(line) strcpy(Options.temppath, line);
  183.                     line = FindToolType(toolarray, "BUFSIZE");
  184.                     if(line) Options.bufsize = atoi(line) > BUFSIZ ? atoi(line) : BUFSIZ;
  185.                     Options.graphiccard = (FindToolType(toolarray, "GRAPHICCARD")) ? TRUE : FALSE;
  186.                     FreeDiskObject(diskobj);
  187.                 }
  188.                 CloseLibrary((struct Library *) IconBase);
  189.             }
  190.             if(_WBenchMsg->sm_NumArgs > 1)
  191.             {
  192.                 if(strlen((char *) diskobjname) > MAXFILENAME)
  193.                 {
  194.                     okmsg("filename is too long!");
  195.                 }
  196.                 else
  197.                 {
  198.                     strcpy(Options.lastfile, diskobjname);
  199.                     strcpy(Options.lastdir, diskobjpath);
  200.                     number_of_pages = splitpage(Options.lastfile);
  201.                     Options.PostOpts.from = 1;
  202.                     Options.PostOpts.to = number_of_pages;
  203.                     argfile = TRUE;
  204.                 }
  205.             }
  206.         }
  207.     }
  208.     else
  209.     {
  210.         for(i=0; i < OPT_COUNT; i++) opts[i] = 0;
  211.         argsptr = ReadArgs(rdargs ? TEMPLATE2 : TEMPLATE1, opts, rdargs);
  212.         if (argsptr == NULL)
  213.         {
  214.             if(rdargs) Fault(IoErr(), "parsing error", undobuff, 256);
  215.             else PrintFault(IoErr(), NULL);
  216.             return(20);
  217.         }
  218.         else
  219.         {
  220.             if (opts[OPT_IFF])
  221.             {
  222.                 if(strlen((char *) opts[OPT_IFF]) > MAXFILENAME)
  223.                 {
  224.                     okmsg("iff-filename is too long!");
  225.                 }
  226.                 else
  227.                 {
  228.                     argiff = TRUE;
  229.                     copy_options(&Options, &IffOptions);
  230.                     strcpy(Options.PostOpts.iffname, (char *) opts[OPT_IFF]);
  231.                     Options.PostOpts.allpages = TRUE;
  232.                     Options.PostOpts.bandrendering = FALSE;
  233.                 }
  234.             }
  235.             if (opts[OPT_PRINTER])
  236.             {
  237.                     argprint = TRUE;
  238.                     copy_options(&Options, &PrintOptions);
  239.                     Options.PostOpts.centerpage = FALSE;
  240.                     Options.PostOpts.formfeed = TRUE;
  241.                     Options.PostOpts.allpages = TRUE;
  242.                     Options.PostOpts.bandrendering = FALSE;
  243.             }
  244.             if (opts[OPT_OPTFILE])
  245.             {
  246.                 LoadPostOptions((char *) opts[OPT_OPTFILE], &Options);
  247.             }
  248.             sptr = (char **) (opts[OPT_FILES]);
  249.             if (sptr)
  250.             {
  251.                 free_list(&Options.startuplist);
  252.                 while (*sptr)
  253.                 {
  254.                     if(strlen(*sptr) > MAXFILENAME)
  255.                     {
  256.                         okmsg("startup-filename is too long!");
  257.                     }
  258.                     else
  259.                     {
  260.                         if(!strcmp(*sptr, "*"))
  261.                         {
  262.                             okmsg("'*' is not a valid filename!");
  263.                             sptr++;
  264.                             continue;
  265.                         }
  266.                         startupnode = (struct startupnode *) malloc(sizeof(struct startupnode));
  267.                         strcpy(startupnode->name, *sptr);
  268.                         startupnode->linknode.ln_Name = startupnode->name;
  269.                         AddTail(&Options.startuplist, (struct Node *) startupnode);
  270.                     }
  271.                     sptr++;
  272.                 }
  273.             }
  274.             if (opts[OPT_NOFF])         Options.PostOpts.formfeed = FALSE;
  275.             if (opts[OPT_CENTER])    Options.PostOpts.centerpage = TRUE;
  276.             if (opts[OPT_SCREEN])     Options.Screen.custscreen = TRUE;
  277.             if (opts[OPT_PUBSCREEN])
  278.             {
  279.                 if(strlen((char *) opts[OPT_PUBSCREEN]) > MAXPUBSCREENNAME)
  280.                 {
  281.                     okmsg("pubscreenname is too long!");
  282.                 }
  283.                 else
  284.                 {
  285.                     strcpy(pubscreenname, (char *) opts[OPT_PUBSCREEN]);
  286.                     Options.Screen.custscreen = FALSE;
  287.                 }
  288.             }
  289.             if (opts[OPT_CONWIN])        argcon = TRUE;
  290.             if (opts[OPT_X])                Options.PostOpts.width = *((LONG *) opts[OPT_X]);
  291.             if (opts[OPT_Y])                Options.PostOpts.height = *((LONG *) opts[OPT_Y]);
  292.             if (opts[OPT_BAND])
  293.             {
  294.                 Options.PostOpts.bandsize = *((LONG *) opts[OPT_BAND]);
  295.                 Options.PostOpts.bandrendering = TRUE;
  296.             }
  297.             if (opts[OPT_XOFF])            Options.PostOpts.xoff = *((LONG *) opts[OPT_XOFF]);
  298.             if (opts[OPT_YOFF])            Options.PostOpts.yoff = *((LONG *) opts[OPT_YOFF]);
  299.             if (opts[OPT_XDEN])            Options.PostOpts.xdpi = *((LONG *) opts[OPT_XDEN]);
  300.             if (opts[OPT_YDEN])            Options.PostOpts.ydpi = *((LONG *) opts[OPT_YDEN]);
  301.             if (opts[OPT_DEN])
  302.             {
  303.                 if (opts[OPT_XDEN] || opts[OPT_YDEN])
  304.                 {
  305.                     okmsg("You can't specify DEN when XDEN or YDEN is specified!");
  306.                 }
  307.                 else
  308.                 {
  309.                     Options.PostOpts.xdpi = *((LONG *) opts[OPT_DEN]);
  310.                     Options.PostOpts.ydpi = *((LONG *) opts[OPT_DEN]);
  311.                 }
  312.             }
  313.             if (opts[OPT_PRDEN])            Options.PostOpts.prden = *((LONG *) opts[OPT_PRDEN]);
  314.             if (opts[OPT_BW])                bw = TRUE;
  315.             if (opts[OPT_RGB])            rgb = TRUE;
  316.             if (opts[OPT_CMYK])            cmyk = TRUE;
  317.  
  318.  
  319.             if (opts[OPT_FONTM])            Options.PostOpts.fonts = *((LONG *) opts[OPT_FONTM]);
  320.             if (opts[OPT_HALFTM])        Options.PostOpts.htone = *((LONG *) opts[OPT_HALFTM]);
  321.             if (opts[OPT_VM])                Options.PostOpts.vm = *((LONG *) opts[OPT_VM]);
  322.             if (opts[OPT_LINEMEM])        Options.PostOpts.paths = *((LONG *) opts[OPT_LINEMEM]);
  323.             if (opts[OPT_FILE])
  324.             {
  325.                 if(strlen((char *) opts[OPT_FILE]) > MAXFILENAME)
  326.                 {
  327.                     okmsg("filename is too long!");
  328.                 }
  329.                 else
  330.                 {
  331.                     strcpy(Options.lastfile, (char *) opts[OPT_FILE]);
  332.                     getpath(Options.lastdir, (char *) opts[OPT_FILE]);
  333.                     number_of_pages = splitpage(Options.lastfile);
  334.                     Options.PostOpts.from = 1;
  335.                     Options.PostOpts.to = number_of_pages;
  336.                     argfile = TRUE;
  337.                 }
  338.             }
  339.             if (opts[OPT_PATH])
  340.             {
  341.                 if(strlen((char *) opts[OPT_PATH]) > MAXFILENAME)
  342.                 {
  343.                     okmsg("pathname is too long!");
  344.                 }
  345.                 else
  346.                 {
  347.                     strcpy(Options.temppath, (char *) opts[OPT_PATH]);
  348.                 }
  349.             }
  350.             if (opts[OPT_BUFSIZE])
  351.             {
  352.                 if( *((LONG *) opts[OPT_BUFSIZE]) > BUFSIZ)
  353.                 {
  354.                     Options.bufsize = *((LONG *) opts[OPT_BUFSIZE]);
  355.                 }
  356.             }
  357.             if (opts[OPT_GRAPHICCARD]) Options.graphiccard = TRUE;
  358.             if (opts[OPT_VERBOSE]) argverbose = TRUE;
  359.             if (opts[OPT_FROM]) Options.PostOpts.from = *((LONG *) opts[OPT_FROM]);
  360.             if (opts[OPT_TO]) Options.PostOpts.to = *((LONG *) opts[OPT_TO]);
  361.             FreeArgs(argsptr);
  362.         }
  363.     }
  364.     if(!argprint && !argiff)
  365.     {
  366.         argwindow = TRUE;
  367.     }
  368.     if(bw)
  369.     {
  370.         if(rgb || cmyk) depth_error = TRUE;
  371.         else Options.PostOpts.depth = 1;
  372.     }
  373.     if(rgb)
  374.     {
  375.         if(bw || cmyk) depth_error = TRUE;
  376.         else Options.PostOpts.depth = 3;
  377.     }
  378.     if(cmyk)
  379.     {
  380.         if(bw || rgb) depth_error = TRUE;
  381.         else Options.PostOpts.depth = 4;
  382.     }
  383.     if(depth_error) okmsg("You can only specify one out of BW, RGB and CMYK!");
  384.     depth_error = FALSE;
  385.     if(argwindow)
  386.     {
  387.         if(argiff || argprint) depth_error = TRUE;
  388.     }
  389.     if(argiff)
  390.     {
  391.         if(argwindow || argprint) depth_error = TRUE;
  392.     }
  393.     if(argprint)
  394.     {
  395.         if(argwindow || argiff) depth_error = TRUE;
  396.     }
  397.     if(depth_error)
  398.     {
  399.         okmsg("You can only specify one out of WINDOW, PRINTER and IFF!");
  400.         argwindow = TRUE;
  401.         argiff = FALSE;
  402.         argprint = FALSE;
  403.     }
  404.     if(Options.PostOpts.prden < 1 || Options.PostOpts.prden > 7) Options.PostOpts.prden = 7;
  405.     if(argwindow) argcon = TRUE;
  406.  
  407. #ifdef OUTPUT_OPTS
  408.     printf("Head: %x, Tail: %d, TailPred: %x\n", Options.startuplist.lh_Head,
  409.                 Options.startuplist.lh_Tail, Options.startuplist.lh_TailPred);
  410.     for(node = Options.startuplist.lh_Head; node->ln_Succ; node = node->ln_Succ)
  411.     {
  412.         printf("node: %x, succ: %x, pred: %x name: %s\n",
  413.                  node, node->ln_Succ, node->ln_Pred, node->ln_Name);
  414.     }
  415.     printf("argiff:      %6d iffname: %s\n", argiff, Options.PostOpts.iffname);
  416.     printf("argprinter:  %6d\n", argprint);
  417.     printf("argwindow:   %6d\n", argwindow);
  418.     printf("xsize:       %6d\n", Options.PostOpts.width);
  419.     printf("ysize:       %6d\n", Options.PostOpts.height);
  420.     printf("bandsize:    %6d\n", Options.PostOpts.bandsize);
  421.     printf("xoff:        %6d\n", Options.PostOpts.xoff);
  422.     printf("yoff:        %6d\n", Options.PostOpts.yoff);
  423.     printf("xden:        %6d\n", Options.PostOpts.xdpi);
  424.     printf("yden:        %6d\n", Options.PostOpts.ydpi);
  425.     printf("printden:    %6d\n", Options.PostOpts.prden);
  426.     printf("depth:       %6d\n", Options.PostOpts.depth);
  427.     printf("fontmem:     %6d\n", Options.PostOpts.fonts);
  428.     printf("halftonemem: %6d\n", Options.PostOpts.htone);
  429.     printf("vmem:        %6d\n", Options.PostOpts.vm);
  430.     printf("linemem:     %6d\n", Options.PostOpts.paths);
  431. #endif
  432.     return(0);
  433. }